<?php
/**
 * $Id: tags_controller.php 7 2009-01-05 19:33:38Z gpo_gigapromoters $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * @version 			$Rev: 7 $
 * @lastModifiedBy		$LastChangedBy: gpo_gigapromoters $
 * @lastChanged			$Date: 2009-01-06 01:03:38 +0530 (Tue, 06 Jan 2009) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Basically handles listing part of tags only.
 *
 */
class TagsController extends TagsAppController
{
	var $name = 'Tags';

	var $helpers  = array('Form','Html');
	var $allowedType;
	//var $components =array('Auth','Session');

	function beforeFilter()
	{
		$this->allowedType = Configure::read('Tag.items');
	//	$this->Auth->allow('index');
		//$this->Auth->userModel = 'User';
		//$this->Auth->autoRedirect = false;
			parent::beforeFilter();
	}

	function index($type,$tag_name)
	{
		if(array_key_exists(ucfirst($type),$this->allowedType))
		{
			$type = ucfirst($type);
			$this->Tag->bindModel(array('hasAndBelongsToMany'=>array('Post'=>array('className'=>'Blog.Post','joinTable'=>'tagged_items','foreignKey'=> 'tag_id', 'associationForeignKey'=> 'item_id','conditions'=> 'Post.status=1','unique'=> true,))),false);
			$tag_data = $this->paginate(array('tag ="'.$tag_name.'"'));
			$this->set('tag_data',$tag_data);
			$categories = $this->Tag->Post->Category->getCategoryListWithCount('Post','Blog',true);
			$recentPosts = $this->Tag->Post->getRecentPost();
			$this->set('type',$type);
			$this->set('tag',$tag_name);
			$this->set('display_field',$this->Tag->{ucfirst($type)}->displayField);
			$this->set('action',ucfirst($type));
			$this->set('categories',$categories);
			$this->set('recentPosts',$recentPosts);
		
		}
	
	}

}

?>